<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    div {
        text-align: center;
    }
    
    input {
        width: 250px;
        height: 30px;
        margin: 30px;
    }
    
    button {
        margin: 30px;
        width: 300px;
        height: 50px;
        background-color: aqua;
        border: none;
        color: white;
    }
</style>

<body>

    <div>
        <h1>登录帐号</h1>
        账号:<input type="text" name="Username">
        <br> 密码:
        <input type="text" name="password">
        <br>
        <button>登录</button>
    </div>

</body>
<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script>
    $("button").eq(0).click(() => {
        $.ajax({
            url: "http://localhost:3000/dl",
            type: "post",
            data: {
                username: $('input').eq(0).val(),
                password: $('input').eq(1).val()
            },
            headers: {
                Authorization: "Bearer " + localStorage.getItem("token")
            },
            dataType: "json",
            success: (res) => {
                console.log(res);
                localStorage.setItem("token", res.token)
                location.assign('./主页.html')
            }
        })
    })
</script>

</html>